Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.4] Model event result prevents firing observable events #18401

Merged
merged 2 commits into from
Mar 18, 2017

Conversation

thijskok
Copy link
Contributor

When a model uses the $event property as well as observable events (e.g., through a 3rd party package), sometimes event handling will stop before reaching the observables. This is because the model's event result is treated as "failed" in Illuminate/Database/Eloquent/Concerns/HasEvents.php, while it isn't:

$result = $this->fireCustomModelEvent($event, $method);

// ...
// For example, one event listener running successfully 
// causes the $result variable to be array(0 => null)
// ...

return ! empty($result) ? $result : static::$dispatcher->{$method}(
    "eloquent.{$event}: ".static::class, $this
);

Empty evaluates the array containing null as false, preventing the dispatcher from firing any subsequent events. The code fragment in this PR strips out the null elements, causing empty to be true when model events were handled successfully.

@taylorotwell taylorotwell merged commit 9eee1fe into laravel:5.4 Mar 18, 2017
@thijskok thijskok deleted the fix-blocking-eloquent-events branch June 10, 2019 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants